﻿@using SCMS.Resource
@model SCMS.UI.Models.TenderAnalysis

@{AjaxOptions ajaxOpts = new AjaxOptions
  {
      UpdateTargetId = "popup-page",
      LoadingElementId = "popup-loading",
      HttpMethod = "Post",
      Url = Url.Action("AuthorizeTA"),
      OnSuccess = "CenterPopup();LoadRequests();"
  };}

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<div class="partialViewCard" style="max-width: 1000px;">
    <div class="partialViewCardHeader">
        <h3>@Resources.TenderAnalysis_String_TenderAnalysisEvaluation</h3>
    </div>
    <br />
    <h4 style="text-align: center;">@Model.EntityTenderAnalysis.RefNumber</h4>
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
        border-collapse: collapse; padding: 5px; font-size: 12px;">
        <tr class="gridheader">
            <th align="center">
                @Resources.Global_String_Date
            </th>
            <th align="center">
                @Resources.Global_String_TenderAnalyaisNo
            </th>
            <th align="center">
                @Resources.Global_String_OrderRequestNo
            </th>
            <th align="center">
                @Resources.Global_String_Currency
            </th>
        </tr>
        <tr class="gridodd">
            <td align="center">
                @Model.EntityTenderAnalysis.AnalysisDate.ToString("dd/MM/yyyy")
            </td>
            <td align="center">
                @Model.EntityTenderAnalysis.RefNumber
            </td>
            <td align="center">
                @Model.EntityTenderAnalysis.OrderRequest.RefNumber
            </td>
            <td align="center">
                @ViewBag.Currency
            </td>
        </tr>
    </table>
    <table width="98%" align="center" cellspacing="0" cellpadding="0">
        <tr>
            <td align="left">
                <p>
                    @Resources.TenderAnalysis_String_TAIntroductionText
                </p>                
            </td>
        </tr>
    </table>
    @if (Model.HasSuppliers)
    {

        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
            border-collapse: collapse; padding: 5px; font-size: 12px;">
            <tr class="gridheader">
                <th align="center">
                    @Resources.Budget_CategoryList_Description
                </th>
                @foreach (var item in Model.SupplierName)
                {
                    <th align="center">
                        @Html.DisplayFor(modelItem => item)
                    </th>
                }
            </tr>
            @{int x = 0; int cols = 1 + Model.SupplierName.Count; }
            @foreach (var item in Model.TBiderQuotes)
            {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.ItemDescription)
                    </td>
                    @foreach (var subItem in item.UnitCost)
                    { 
                        <td align="right">
                            @subItem.ToString("#,##0.00")
                        </td>
                    }
                </tr>
            }
            @if (Model.TransportCost.Count > 0)
            {
                <tr>
                    <td>
                        @Resources.Global_String_TransportCost
                    </td>
                    @foreach (var item in Model.TransportCost)
                    {
                        <td align="right">
                            @item.ToString("#,##0.00")
                        </td>
                    }
                </tr>
            }
            <tr>
                <td>
                    @Resources.Global_String_TotalCost
                </td>
                @foreach (var item in Model.TotalCost)
                {
                    <td align="right">
                        @item.ToString("#,##0.00")
                    </td>
                }
            </tr>
            <tr class="gridheader">
                <td align="center" colspan=@cols>
                    @Resources.Global_String_TermsAndConditions
                </td>
            </tr>
            @if (Model.ShippingTerm.Count > 0)
            {
                <tr>
                    <td>
                        @Resources.Global_String_ShippingTerms
                    </td>
                    @foreach (var item in Model.ShippingTerm)
                    {
                        <td>@Html.DisplayFor(modelItem => item)
                        </td>
                    }
                </tr>
            }
            @if (Model.DeliveryTime.Count > 0)
            {
                <tr>
                    <td>
                        @Resources.GoodsReceivedNote_LoadGRNVerifyItems_DeliveryDate
                    </td>
                    @foreach (var item in Model.DeliveryTime)
                    {
                        <td>
                            @item.ToString("dd/MM/yyyy")
                        </td>
                    }
                </tr>
            }
            @if (Model.Warrant.Count > 0)
            {
                <tr>
                    <td>
                        @Resources.TenderAnalysis_String_Warranty
                    </td>
                    @foreach (var item in Model.Warrant)
                    {
                        <td>@Html.DisplayFor(modelItem => item)
                        </td>
                    }
                </tr>
            }
            @if (Model.TermzOfPayment.Count > 0)
            {
                <tr>
                    <td>
                        @Resources.Global_String_PaymentTerms
                    </td>
                    @foreach (var item in Model.TermzOfPayment)
                    {
                        <td>@Html.DisplayFor(modelItem => item)
                        </td>
                    }
                </tr>
            }
            @if (Model.others.Count > 0)
            {
                <tr>
                    <td>
                        @Resources.Global_String_Other
                    </td>
                    @foreach (var item in Model.others)
                    {
                        <td>@Html.DisplayFor(modelItem => item)
                        </td>
                    }
                </tr>
            }
        </table>
    }
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
        border-collapse: collapse; padding: 5px; font-size: 12px;">
        <tr class="gridheader">
            <th style="width: 30%;">
                @Resources.TenderAnalysis_String_AnalysisPreparedBy
            </th>
            <th style="width: 30%;">
                @Resources.Global_String_Title
            </th>
            <th style="width: 20%;">
                @Resources.Global_String_Date
            </th>
            <th style="width: 20%;">
                @Resources.Global_String_Signature
            </th>
        </tr>
        <tr>
            <td align="center">
                @Model.EntityTenderAnalysis.Staff1.Person.FirstName &nbsp; @Model.EntityTenderAnalysis.Staff1.Person.OtherNames
            </td>
            <td align="center">
                @Model.EntityTenderAnalysis.Staff1.Designation.Name
            </td>
            <td align="center">
                @Model.EntityTenderAnalysis.PreparedOn.Value.ToString("dd/MM/yyyy h:mm tt")
            </td>
            <td align="center">
                @if (Model.EntityTenderAnalysis.Staff1 != null && Model.EntityTenderAnalysis.Staff1.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.EntityTenderAnalysis.Staff1.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                }
            </td>
        </tr>
    </table>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
        border-collapse: collapse; padding: 5px; font-size: 12px;">
        <tr class="gridheader">
            <th style="width: 19%;" class="gridheader">
                @Resources.Approver_ApproverList_Authorization
            </th>
            <th style="width: 27%;">
                @Resources.TenderAnalysis_String_TenderConclusionApprovedBy
            </th>
            <th style="width: 27%;">
                @Resources.TenderAnalysis_String_TenderConclusionApprovedBy
            </th>
            <th style="width: 27%;">
                @Resources.TenderAnalysis_String_TenderConclusionAuthorizedBy
            </th>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.TenderAnalysis_String_SupplierChosen:
            </td>
            <td align="center">
                @if (Model.TenderEvaluators.Count > 0 && Model.TenderEvaluators[0].Priority != 3 && Model.TenderEvaluators[0].HasApproved != null)
                {
                    if (Model.TenderEvaluators[0].RecommendedSupplierId != null)
                    { 
                        <b>@Model.TenderEvaluators[0].Supplier.Name</b>
                    }
                }
            </td>
            <td align="center">
                @if (Model.TenderEvaluators.Count > 1 && Model.TenderEvaluators[1].Priority != 3 && Model.TenderEvaluators[1].HasApproved != null)
                {
                    if (Model.TenderEvaluators[1].RecommendedSupplierId != null)
                    { 
                        <b>@Model.TenderEvaluators[1].Supplier.Name</b>
                    }
                }
            </td>
            <td align="center">
                @if (Model.TenderEvaluators.Count > 2 && Model.TenderEvaluators[2].Priority == 3 && Model.TenderEvaluators[2].HasApproved != null)
                {
                    if (Model.TenderEvaluators[2].RecommendedSupplierId != null)
                    { 
                        <font color="blue"><h4>@Model.TenderEvaluators[2].Supplier.Name</h4></font>
                    }
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Remarks:
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 0 && Model.TenderEvaluators[0].Priority != 3 && Model.TenderEvaluators[0].HasApproved != null)
                {
                    @Model.TenderEvaluators[0].Remarks
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 1 && Model.TenderEvaluators[1].Priority != 3 && Model.TenderEvaluators[1].HasApproved != null)
                {
                    @Model.TenderEvaluators[1].Remarks
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 2 && Model.TenderEvaluators[2].Priority == 3 && Model.TenderEvaluators[2].HasApproved != null)
                {
                    @Model.TenderEvaluators[2].Remarks
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Name:
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 0 && Model.TenderEvaluators[0].Priority != 3)
                { 
                    @Model.TenderEvaluators[0].Staff.Person.FirstName
                    @Html.Raw("&nbsp;")
                    @Model.TenderEvaluators[0].Staff.Person.OtherNames
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 1 && Model.TenderEvaluators[1].Priority != 3)
                { 
                    @Model.TenderEvaluators[1].Staff.Person.FirstName
                    @Html.Raw("&nbsp;")
                    @Model.TenderEvaluators[1].Staff.Person.OtherNames
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 2 && Model.TenderEvaluators[2].Priority == 3)
                { 
                    @Model.TenderEvaluators[2].Staff.Person.FirstName
                    @Html.Raw("&nbsp;")
                    @Model.TenderEvaluators[2].Staff.Person.OtherNames
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Title:
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 0 && Model.TenderEvaluators[0].Priority != 3)
                { 
                    @Model.TenderEvaluators[0].Staff.Designation.Name
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 1 && Model.TenderEvaluators[1].Priority != 3)
                { 
                    @Model.TenderEvaluators[1].Staff.Designation.Name
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 2 && Model.TenderEvaluators[2].Priority == 3)
                { 
                    @Model.TenderEvaluators[2].Staff.Designation.Name
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Date:
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 0 && Model.TenderEvaluators[0].Priority != 3 && Model.TenderEvaluators[0].HasApproved != null)
                { 
                    @Model.TenderEvaluators[0].DateApproved.Value.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 1 && Model.TenderEvaluators[1].Priority != 3 && Model.TenderEvaluators[1].HasApproved != null)
                { 
                    @Model.TenderEvaluators[1].DateApproved.Value.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 2 && Model.TenderEvaluators[2].Priority == 3 && Model.TenderEvaluators[2].HasApproved != null)
                { 
                    @Model.TenderEvaluators[2].DateApproved.Value.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Signature:
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 0 && Model.TenderEvaluators[0].Priority != 3 && Model.TenderEvaluators[0].HasApproved != null)
                {
                    if (Model.TenderEvaluators[0].Staff.Person.SignatureImage != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.TenderEvaluators[0].Staff.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                    }
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 1 && Model.TenderEvaluators[1].Priority != 3 && Model.TenderEvaluators[1].HasApproved != null)
                {
                    if (Model.TenderEvaluators[1].Staff.Person.SignatureImage != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.TenderEvaluators[1].Staff.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                    }
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 2 && Model.TenderEvaluators[2].Priority == 3 && Model.TenderEvaluators[2].HasApproved != null)
                {
                    if (Model.TenderEvaluators[2].Staff.Person.SignatureImage != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.TenderEvaluators[2].Staff.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                    }
                }
            </td>
        </tr>
    </table>
    <br />
    @using (Ajax.BeginForm(null, null, ajaxOpts, new { @class = "form" }))
    {
        @Html.ValidationSummary(true)
        <table width="98%" align="center" style="border: 1px solid grey; border-collapse: collapse; padding: 5px; font-size: 12px;">
            <tr class="gridheader">
                <td colspan="2">@Resources.TenderAnalysis_String_RecommendSupplier</td>
            </tr>
            <tr>
                <td align="right" width="40%">@Resources.TenderAnalysis_String_SelectSupplier:</td>
                <td width="60%">
                    @Html.DropDownListFor(m => m.RecommendedSupplierId, Model.Suppliers)
                    @Html.ValidationMessageFor(m => m.RecommendedSupplierId)
                </td>
            </tr>
            <tr>
                <td align="right" valign="top">@Resources.Global_String_Remarks:</td>
                <td>
                    @Html.TextAreaFor(m => m.Remarks)
                    @Html.HiddenFor(m => m.EntityTenderAnalysis.Id)
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="submit" class="btn tertiary"  value="@Resources.Global_String_Authorize" />
                    &nbsp; &nbsp;
                    <input type="button" class="btn tertiary"  value=" @Resources.Global_String_Reject " onclick="sendRequest('/RequestReview/LoadRejectTA/@Model.EntityTenderAnalysis.Id', 'popup-page', 'popup-loading'); CenterPopup();" />
                </td>
            </tr>
        </table>
    }
    <br />
</div>